﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Project.Module.DAO.BL;
using Project.Module.Model;
using Project.Engine.Utilities;
using Project.Engine.Control;
using Project.Module.View;
using Project.Module.View.CMS;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;


namespace Project.Module.Controller
{
    public partial class HomeController : System.Web.Mvc.Controller
    {
        public ActionResult Index()
        {
            string displayUser = String.Empty;
            if (Session["username"] != null && ((string)(Session["username"])).Length > 0)
            {
                displayUser = ConvertUtil.ToString(Session["username"]);
            }

            string url = this.HttpContext.Request.Url.AbsolutePath;
            string rawurl = this.HttpContext.Request.Url.AbsoluteUri.ToString();
            string[] arr = rawurl.Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries);

            #region JSON
            if (url == "/reg")
            {
                return this.RegAccount(this.Request["name"], this.Request["email"], this.Request["address"], this.Request["city"], this.Request["phoneHome"], this.Request["mobile"], this.Request["pass"], this.Request["auPass"]);
            }
            else if (url == "/login")
            {
                return this.LoginAccount(this.Request["name"], this.Request["pass"]);
            }
            else if (url == "/reset-pass")
            {
                return this.ResetPass(this.Request["mail"], this.Request["name"]);
            }
            else if (url == "/gui-lien-he")
            {
                return this.GuiLienHe(this.Request["name"], this.Request["content"]);
            }

            // gui binh luan
            //-------------------------------------
            // gui binh luan trong chi tiet su kien
            else if (url == "/su-kien/binh-luan")
            {
                return this.SendComment(this.Request["comment"], this.Request["url"]);
            }
            // gui binh luan trong chi tiet lop hoc
            else if (url == "/lop-hoc/binh-luan")
            {
                return this.SendCommentProduct(this.Request["comment"], this.Request["url"]);
            }
            // gui binh luan trong nguyen lieu lam banh
            else if (url == "/nguyen-lieu-lam-banh/binh-luan")
            {
                return this.SendCommentProduct(this.Request["comment"], this.Request["url"]);
            }
            // gui binh luan trong nguyen lieu trang tri
            else if (url == "/nguyen-lieu-trang-tri/binh-luan")
            {
                return this.SendCommentProduct(this.Request["comment"], this.Request["url"]);
            }
            // gui binh luan trong do gia dung 
            else if (url == "/do-gia-dung/binh-luan")
            {
                return this.SendCommentProduct(this.Request["comment"], this.Request["url"]);
            }
            // gui binh luan trong dung cu lam banh 
            else if (url == "/dung-cu-lam-banh/binh-luan")
            {
                return this.SendCommentProduct(this.Request["comment"], this.Request["url"]);
            }
            // gui binh luan trong khuon
            else if (url == "/khuon/binh-luan")
            {
                return this.SendCommentProduct(this.Request["comment"], this.Request["url"]);
            }
            // gui binh luan trong sach
            else if (url == "/sach/binh-luan")
            {
                return this.SendCommentProduct(this.Request["comment"], this.Request["url"]);
            }
            // gui binh luan cong thuc
            else if (url == "/cong-thuc/binh-luan")
            {
                return this.SendCommentProduct(this.Request["comment"], this.Request["url"]);
            }
            else if (url.IndexOf("/thoat") >= 0)
            {
                return this.Logout();
            }

            #endregion

            else if (url.IndexOf("/quen-mat-khau") >= 0)
            {
                return View("/Views/Home/ForgotPass.cshtml");
            }
            else if (url.IndexOf("/lay-lai-mat-khau") >= 0)
            {
                return View("/Views/Home/ResetPass.cshtml");
            }
            else if (url.IndexOf("/dang-ky") >= 0 && arr.Length == 1)
            {
                return View("/Views/Home/Reg.cshtml");
            }
            else if (url.IndexOf("/lien-he") >= 0 && arr.Length == 1)
            {
                return View("/Views/Home/LienHe.cshtml");
            }
            else if (url.IndexOf("/gioi-thieu") >= 0 && arr.Length == 1)
            {
                return View("/Views/Home/GioiThieu.cshtml");
            }
            else if (url.IndexOf("/dang-nhap") >= 0 && arr.Length == 1)
            {
                return View("/Views/Home/Login.cshtml");
            }

            #region searching
            else if (url.IndexOf("tim-kiem") >= 0)
            {
                return View("~/views/home/ResultSearch.cshtml");
            }
            else if (url.IndexOf("search") >= 0)
            {
                return View("~/views/home/ResultSearch.cshtml");
            }
            #endregion

            #region gio hang
            // xem gio hang
            else if (url.IndexOf("/gio-hang") >= 0 && arr.Length == 2)
            {
                return View("/Views/Home/GioHang.cshtml");
            }
            // them gio hang
            else if (url.IndexOf("gio-hang") >= 0 && arr.Length == 3 && rawurl.Contains("?add=") == true)
            {
                string nameCustomer = arr[1].Replace("name=", String.Empty);
                if (String.IsNullOrEmpty(nameCustomer) == true)
                {
                    return View("/Views/Error/Error.cshtml");
                }
                else
                {
                    int idProduct = ConvertUtil.ToInt32(arr[2].Replace("add=", String.Empty));
                    return this.AddCart(nameCustomer, idProduct);
                }
            }
            // xoa gio hang
            else if (url.IndexOf("gio-hang") >= 0 && arr.Length == 4 && rawurl.Contains("gio-hang?del?") == true)
            {
                string nameCustomer = arr[2].Replace("name=", String.Empty);
                int idCart = ConvertUtil.ToInt32(arr[3].Replace("id=", String.Empty));
                return this.DeleteCart(nameCustomer, idCart);
            }
            else if (url.IndexOf("gio-hang") >= 0 && arr.Length == 3 && rawurl.Contains("thanhtoan") == true) {
                string userName = ConvertUtil.ToString(Session["username"]);
                CustomerBL cus = new CustomerBL();
                CustomerModel customerInfor = cus.GetUserInformation(userName);
                ViewBag.customerInfor = customerInfor;
                
                return View("/Views/Home/phuongthuc.cshtml");
            }// thanh toan
            else if (url.IndexOf("gio-hang") >= 0 && (arr.Length == 4 || arr.Length == 5) && rawurl.Contains("gio-hang?buy?") == true)
            {
                // Get user information
                string userName = ConvertUtil.ToString(Session["username"]);
                CustomerBL cus = new CustomerBL();
                CustomerModel customerInfor = cus.GetUserInformation(userName);
                ViewBag.customerInfor = customerInfor;

                if (rawurl.Contains("?phuongthuc2"))
                {
                    int idCart = ConvertUtil.ToInt32(arr[3].Replace("id=", String.Empty));
                    ViewBag.idCart = idCart;
                    return View("/Views/Home/phuongthuc2.cshtml");
                }
                else
                {
                    if (rawurl.Contains("?thanhtoan"))
                    {
                        string nameCustomer = arr[2].Replace("name=", String.Empty);
                        int idCart = ConvertUtil.ToInt32(arr[3].Replace("id=", String.Empty));
                        return this.BuyCart(nameCustomer, idCart);
                    }
                    else
                    {
                        int idCart = ConvertUtil.ToInt32(arr[3].Replace("id=", String.Empty));
                        ViewBag.idCart = idCart;
                        return View("/Views/Home/phuongthuc.cshtml");
                    }

                }

            }
            #endregion

            #region su kien
            else if (url.IndexOf("/su-kien") >= 0 && arr.Length == 1)
            {
                return View("/Views/Home/SuKien.cshtml");
            }
            // chi tiet su kien
            else if (url.IndexOf("/su-kien") >= 0 && arr.Length == 3 && rawurl.Contains("/su-kien?id=") == true)
            {
                int idEvent = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                string alias = arr[2];
                DocumentInfo document = new ChiTietSuKienView(idEvent, alias);
                return View("/Views/Home/ChiTietSuKien.cshtml", new TreeNodeInfo(idEvent, document));
            }
            #endregion

            #region lop hoc
            else if (url.IndexOf("lop-hoc") >= 0)
            {
                if (arr.Length == 1)
                {
                    return View("/Views/Home/LopHoc.cshtml");
                } // chi tiet lop hoc
                else if (arr.Length == 3 && rawurl.Contains("/lop-hoc?id=") == true)
                {
                    int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                    string alias = arr[2];
                    DocumentInfo document = new ChiTietLopHocView(id, alias);
                    return View("/Views/Home/ChiTietLopHoc.cshtml", new TreeNodeInfo(id, document));
                }
            }
            #endregion

            #region nguyen lieu lam banh
            else if (url.IndexOf("nguyen-lieu-lam-banh") >= 0)
            {
                if (arr.Length <= 2)
                {
                    string alias = rawurl;
                    DocumentInfo document = new Catagory(0, alias, displayUser);
                    return View("/Views/Home/CategoryView.cshtml", new TreeNodeInfo(0, document));
                } // chi tiet nguyen lieu lam banh
                else if (arr.Length == 3 && rawurl.Contains("/nguyen-lieu-lam-banh?id=") == true)
                {
                    int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                    string alias = arr[2];
                    DocumentInfo document = new ChiTietNguyenLieuLamBanhView(id, alias);
                    return View("/Views/Home/ChiTietNguyenLieuLamBanh.cshtml", new TreeNodeInfo(id, document));
                }
            }
            #endregion

            #region nguyen lieu trang tri
            else if (url.IndexOf("nguyen-lieu-trang-tri") >= 0)
            {
                if (arr.Length <= 2)
                {
                    string alias = rawurl;
                    DocumentInfo document = new Catagory(0, alias, displayUser);
                    return View("/Views/Home/CategoryView.cshtml", new TreeNodeInfo(0, document));
                } // chi tiet nguyen lieu trang tri
                else if (arr.Length == 3 && rawurl.Contains("/nguyen-lieu-trang-tri?id=") == true)
                {
                    int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                    string alias = arr[2];
                    DocumentInfo document = new ChiTietNguyenLieuTrangTriView(id, alias);
                    return View("/Views/Home/ChiTietNguyenLieuTrangTri.cshtml", new TreeNodeInfo(id, document));
                }
            }
            #endregion

            #region dung cu lam banh
            else if (url.IndexOf("dung-cu-lam-banh") >= 0)
            {
                if (arr.Length <= 2)
                {
                    string alias = rawurl;
                    DocumentInfo document = new Catagory(0, alias, displayUser);
                    return View("/Views/Home/CategoryView.cshtml", new TreeNodeInfo(0, document));
                } // chi tiet dung cu lam banh
                else if (arr.Length == 3 && rawurl.Contains("/dung-cu-lam-banh?id=") == true)
                {
                    int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                    string alias = arr[2];
                    DocumentInfo document = new ChiTietDungCuLamBanhView(id, alias);
                    return View("/Views/Home/ChiTietDungCuLamBanh.cshtml", new TreeNodeInfo(id, document));
                }
            }
            #endregion

            #region khuon
            else if (url.IndexOf("khuon") >= 0)
            {
                if (arr.Length <= 2)
                {
                    string alias = rawurl;
                    DocumentInfo document = new Catagory(0, alias, displayUser);
                    return View("/Views/Home/CategoryView.cshtml", new TreeNodeInfo(0, document));
                } // chi tiet khuon
                else if (arr.Length == 3 && rawurl.Contains("/khuon?id=") == true)
                {
                    int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                    string alias = arr[2];
                    DocumentInfo document = new ChiTietKhuonView(id, alias);
                    return View("/Views/Home/ChiTietKhuon.cshtml", new TreeNodeInfo(id, document));
                }
            }
            #endregion

            #region do gia dung
            else if (url.IndexOf("do-gia-dung") >= 0)
            {
                if (arr.Length <= 2)
                {
                    string alias = rawurl;
                    DocumentInfo document = new Catagory(0, alias, displayUser);
                    return View("/Views/Home/CategoryView.cshtml", new TreeNodeInfo(0, document));
                } // chi tiet do gia dung
                else if (arr.Length == 3 && rawurl.Contains("/do-gia-dung?id=") == true)
                {
                    int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                    string alias = arr[2];
                    DocumentInfo document = new ChiTietDoGiaDungView(id, alias);
                    return View("/Views/Home/ChiTietDoGiaDung.cshtml", new TreeNodeInfo(id, document));
                }
            }
            #endregion

            #region sach
            else if (url.IndexOf("sach") >= 0)
            {
                if (arr.Length <= 2)
                {
                    string alias = rawurl;
                    DocumentInfo document = new Catagory(0, alias, displayUser);
                    return View("/Views/Home/CategoryView.cshtml", new TreeNodeInfo(0, document));
                } // chi tiet sach
                else if (arr.Length == 3 && rawurl.Contains("/sach?id=") == true)
                {
                    int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                    string alias = arr[2];
                    DocumentInfo document = new ChiTietSachView(id, alias);
                    return View("/Views/Home/ChiTietSach.cshtml", new TreeNodeInfo(id, document));
                }
            }
            #endregion

            #region cong thuc
            else if (url.IndexOf("cong-thuc") >= 0)
            {
                if (arr.Length <= 2)
                {
                    string alias = rawurl;
                    DocumentInfo document = new Catagory(0, alias, displayUser);
                    return View("/Views/Home/CategoryView.cshtml", new TreeNodeInfo(0, document));
                } // chi tiet cong thu
                else if (arr.Length == 3 && rawurl.Contains("/cong-thuc?id=") == true)
                {
                    int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                    string alias = arr[2];
                    DocumentInfo document = new ChiTietCongThucView(id, alias);
                    return View("/Views/Home/ChiTietCongThuc.cshtml", new TreeNodeInfo(id, document));
                }
            }
            #endregion

            #region cms
            string displayAdmin = String.Empty;
            if (Session["username_ad"] != null && ((string)(Session["username_ad"])).Length > 0)
            {
                displayAdmin = ConvertUtil.ToString(Session["username_ad"]);
            }

            if (url.ToLower() == "/admin")
            {
                return View("/Views/Backend/Home/Login.cshtml");
            }
            else if (url.IndexOf("/admin/trang-chu") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                return View("/Views/Backend/Home/Index.cshtml");
            }

            #region JSON
            else if (url == "/admin/login")
            {
                return this.CMSLoginAccount(Request["name"].ToString(), Request["pass"].ToString());
            }
            else if (url == "/admin/reg")
            {
                return this.CMSRegAccount(Request["name"].ToString(), Request["email"].ToString(), Request["pass"].ToString());
            }
            else if (url.IndexOf("/admin/thoat") >= 0)
            {
                return this.CMSLogout();
            }
            else if (url == "/admin/addProduct")
            {
                return this.AddNewProduct(Request["name"].ToString(), Request["image"], ConvertUtil.ToInt32(Request["quantity"]), ConvertUtil.ToInt32(Request["price"]), Request["description"].ToString(), ConvertUtil.ToInt32(Request["cateId"]), ConvertUtil.ToInt32(Request["supplierId"]), displayAdmin);
            }
            else if (url == "/admin/editProduct")
            {
                string _url = ConvertUtil.ToString(Request["id"]).Replace("http://", String.Empty);
                string[] _arr = _url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                return this.EditProduct(ConvertUtil.ToInt32(_arr[3].Replace("id=", "")), Request["name"].ToString(), Request["image"], ConvertUtil.ToInt32(Request["quantity"]), ConvertUtil.ToInt32(Request["price"]), Request["description"].ToString(), ConvertUtil.ToInt32(Request["cateId"]), ConvertUtil.ToInt32(Request["supplierId"]), displayAdmin);
            }
            else if (url == "/admin/addSupplier")
            {
                return this.AddNewSupplier(Request["name"].ToString(), Request["description"].ToString(), Request["address"].ToString(), displayAdmin);
            }
            else if (url == "/admin/editSupplier")
            {
                string _url = ConvertUtil.ToString(Request["id"]).Replace("http://", String.Empty);
                string[] _arr = _url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                return this.EditSupplier(ConvertUtil.ToInt32(_arr[3].Replace("id=", "")), Request["name"].ToString(), Request["description"].ToString(), Request["address"].ToString(), displayAdmin);
            }
            else if (url == "/admin/editAccount")
            {
                string _url = ConvertUtil.ToString(Request["id"]).Replace("http://", String.Empty);
                string[] _arr = _url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                return this.CMSEditAccount(ConvertUtil.ToInt32(_arr[3].Replace("id=", "")), Request["email"].ToString(), Request["pass"].ToString());
            }
            else if (url == "/admin/addNews")
            {
                return this.AddNews(Request["title"].ToString(), Request["content"], Request["status"]);
            }
            else if (url == "/admin/editNews")
            {
                string _url = ConvertUtil.ToString(Request["id"]).Replace("http://", String.Empty);
                string[] _arr = _url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                return this.EditNews(ConvertUtil.ToInt32(_arr[3].Replace("id=", "")), Request["title"].ToString(), Request["content"], Request["status"]);
            }
            #endregion

            #region quan ly nhom quyen
            else if (url.IndexOf("/admin/dang-ki-tai-khoan") >= 0 && displayAdmin == "admin")
            {
                return View("/Views/Backend/Home/DangKiTaiKhoan.cshtml");
            }
            else if (url.IndexOf("/admin/quan-ly-nhom-quyen") >= 0 && displayAdmin == "admin" && arr.Length == 1)
            {
                string alias = rawurl;
                DocumentInfo document = new Catagory(0, alias, displayAdmin);
                return View("/Views/Backend/Home/QuanLyNhomQuyen.cshtml", new TreeNodeInfo(0, document));
            } // delete user
            else if (url.IndexOf("/admin/quan-ly-nhom-quyen/del") >= 0 && displayAdmin == "admin")
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                return this.DeleleUser(id);
            }
            // chinh sua user
            else if (url.IndexOf("/admin/quan-ly-nhom-quyen/edit") >= 0 && displayAdmin == "admin")
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                return Redirect("/admin/chinh-sua-nhom-quyen/id=" + id);
            }
            else if (url.IndexOf("/admin/chinh-sua-nhom-quyen/id=") >= 0 && displayAdmin == "admin")
            {
                int id = ConvertUtil.ToInt32(url.Replace("/admin/chinh-sua-nhom-quyen/id=", String.Empty));
                DocumentInfo document = new CMSEditTaiKhoan(id, null);
                return View("/Views/Backend/Home/ChinhSuaTaiKhoan.cshtml", new TreeNodeInfo(id, document));
            }
            #endregion

            #region quan ly comment
            else if (url.IndexOf("/admin/quan-ly-phan-hoi") >= 0 && arr.Length == 1 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                string alias = rawurl;
                DocumentInfo document = new Catagory(0, alias, displayAdmin);
                return View("/Views/Backend/Home/QuanLyPhanHoi.cshtml", new TreeNodeInfo(0, document));
            } // delete comment
            else if (url.IndexOf("/admin/quan-ly-phan-hoi/del") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                return this.DeleteComment(id);
            }
            #endregion

            #region quan ly cong thuc
            // them moi san pham
            //else if (url.IndexOf("/admin/them-san-pham") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            //{
            //    return View("/Views/Backend/Home/ThemSanPham.cshtml");
            //}
            else if (url.IndexOf("/admin/quan-ly-cong-thuc") >= 0 && String.IsNullOrEmpty(displayAdmin) == false && arr.Length == 1)
            {
                return View("/Views/Backend/Home/QuanLyCongThuc.cshtml");
            }
            //// xoa san pham
            //else if (url.IndexOf("/admin/quan-ly-san-pham/del") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            //{
            //    int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
            //    return this.DeleteProduct(id);
            //}
            //// chinh sua san pham
            //else if (url.IndexOf("/admin/quan-ly-san-pham/edit") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            //{
            //    int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
            //    return Redirect("/admin/chinh-sua-san-pham/id=" + id);
            //}
            //else if (url.IndexOf("/admin/chinh-sua-san-pham/id=") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            //{
            //    int id = ConvertUtil.ToInt32(url.Replace("/admin/chinh-sua-san-pham/id=", String.Empty));
            //    DocumentInfo document = new CMSEditSanPhamView(id, null);
            //    return View("/Views/Backend/Home/ChinhSuaSanPham.cshtml", new TreeNodeInfo(id, document));
            //}
            #endregion

            #region quan ly san pham
            // them moi san pham
            else if (url.IndexOf("/admin/them-san-pham") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                return View("/Views/Backend/Home/ThemSanPham.cshtml");
            }
            else if (url.IndexOf("/admin/quan-ly-san-pham") >= 0 && String.IsNullOrEmpty(displayAdmin) == false && arr.Length == 1)
            {
                return View("/Views/Backend/Home/QuanLySanPham.cshtml");
            }
            // xoa san pham
            else if (url.IndexOf("/admin/quan-ly-san-pham/del") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                return this.DeleteProduct(id);
            }
            // chinh sua san pham
            else if (url.IndexOf("/admin/quan-ly-san-pham/edit") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                return Redirect("/admin/chinh-sua-san-pham/id=" + id);
            }
            else if (url.IndexOf("/admin/chinh-sua-san-pham/id=") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(url.Replace("/admin/chinh-sua-san-pham/id=", String.Empty));
                DocumentInfo document = new CMSEditSanPhamView(id, null);
                return View("/Views/Backend/Home/ChinhSuaSanPham.cshtml", new TreeNodeInfo(id, document));
            }
            #endregion
            #region quan ly nha cung cap
            // them nha cung cap
            else if (url.IndexOf("/admin/them-nha-cung-cap") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                return View("/Views/Backend/Home/ThemNhaCungCap.cshtml");
            }
            else if (url.IndexOf("/admin/quan-ly-nha-cung-cap") >= 0 && String.IsNullOrEmpty(displayAdmin) == false && arr.Length == 1)
            {
                string alias = rawurl;
                DocumentInfo document = new Catagory(0, alias, displayAdmin);
                return View("/Views/Backend/Home/QuanLyNhaCungCap.cshtml", new TreeNodeInfo(0, document));
            } // delete supplier
            else if (url.IndexOf("/admin/quan-ly-nha-cung-cap/del") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                return this.DeleteSupplier(id);
            }
            // chinh sua san pham
            else if (url.IndexOf("/admin/quan-ly-nha-cung-cap/edit") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                return Redirect("/admin/chinh-sua-nha-cung-cap/id=" + id);
            }
            else if (url.IndexOf("/admin/chinh-sua-nha-cung-cap/id=") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(url.Replace("/admin/chinh-sua-nha-cung-cap/id=", String.Empty));
                DocumentInfo document = new CMSEditSupplierView(id, null);
                return View("/Views/Backend/Home/ChinhSuaNhaCungCap.cshtml", new TreeNodeInfo(id, document));
            }
            #endregion

             #region quan ly dat hang
            else if (url.IndexOf("/admin/quan-ly-dat-hang") >= 0 && String.IsNullOrEmpty(displayAdmin) == false && arr.Length == 1)
            {
                string alias = rawurl;
                DocumentInfo document = new Catagory(0, alias, displayAdmin);
                return View("/Views/Backend/Home/QuanLyDatHang.cshtml", new TreeNodeInfo(0, document));
            } // delete dat hang
            else if (url.IndexOf("/admin/quan-ly-dat-hang/del") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                return this.DeleteCartInCMS(id);
            }
                //chi tiet don hang
            else if (url.IndexOf("/admin/quan-ly-dat-hang/detail") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                DocumentInfo document = new ChiTietDonHangView(id, null);
                return View("/Views/Backend/Home/ChiTietDonHang.cshtml", new TreeNodeInfo(0, document));
            }
            #endregion

            #region quan ly bai viet
            // them bai viet
            else if (url.IndexOf("/admin/them-bai-viet") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                return View("/Views/Backend/Home/ThemBaiViet.cshtml");
            }
            else if (url.IndexOf("/admin/quan-ly-bai-viet") >= 0 && String.IsNullOrEmpty(displayAdmin) == false && arr.Length == 1)
            {
                string alias = rawurl;
                DocumentInfo document = new Catagory(0, alias, displayAdmin);
                return View("/Views/Backend/Home/QuanLyBaiViet.cshtml", new TreeNodeInfo(0, document));
            } // delete bai viet
            else if (url.IndexOf("/admin/quan-ly-bai-viet/del") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                return this.DeleteNews(id);
            }
            // chinh sua bai viet
            else if (url.IndexOf("/admin/quan-ly-bai-viet/edit") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(arr[1].Replace("id=", String.Empty));
                return Redirect("/admin/chinh-sua-bai-viet/id=" + id);
            }
            else if (url.IndexOf("/admin/chinh-sua-bai-viet/id=") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                int id = ConvertUtil.ToInt32(url.Replace("/admin/chinh-sua-bai-viet/id=", String.Empty));
                DocumentInfo document = new CMSEditNewsView(id, null);
                return View("/Views/Backend/Home/ChinhSuaBaiViet.cshtml", new TreeNodeInfo(id, document));
            }
            #endregion

            #region searching
            // tim kiem user 
            else if (url.IndexOf("/admin/tim-nguoi-dung") >= 0 && displayAdmin == "admin")
            {
                return View("/Views/Backend/Home/TimKiemNguoiDung.cshtml");
            }
            else if (url.IndexOf("/admin/admin-nguoi-dung") >= 0 && displayAdmin == "admin")
            {
                return View("/Views/Backend/Home/TimKiemNguoiDung.cshtml");
            }
            // tim kiem bai viet
            else if (url.IndexOf("/admin/tim-bai-viet") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                return View("/Views/Backend/Home/TimKiemBaiViet.cshtml");
            }
            else if (url.IndexOf("/admin/admin-bai-viet") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                return View("/Views/Backend/Home/TimKiemBaiViet.cshtml");
            }
            // tim kiem san pham
            else if (url.IndexOf("/admin/tim-san-pham") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                return View("/Views/Backend/Home/TimKiemSanPham.cshtml");
            }
            else if (url.IndexOf("/admin/admin-san-pham") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                return View("/Views/Backend/Home/TimKiemSanPham.cshtml");
            }
            // tim kiem nha cung cap
            else if (url.IndexOf("/admin/tim-nha-cung-cap") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                return View("/Views/Backend/Home/TimKiemNhaCungCap.cshtml");
            }
            else if (url.IndexOf("/admin/admin-nha-cung-cap") >= 0 && String.IsNullOrEmpty(displayAdmin) == false)
            {
                return View("/Views/Backend/Home/TimKiemNhaCungCap.cshtml");
            }
            #endregion

            #endregion

            return View("/Views/Home/Index.cshtml");
        }

    }
}
